import time
import Login
import WordBook
import db


def welcome():
    print("""
        ===========================================
                    欢迎来到单词默写系统
                        1、登陆
                        2、注册
                        0、退出
        ===========================================     
        """)
    while True:
        choose = input("请选择你的功能：").strip()
        if choose == "1":
            return 1
        elif choose == "2":
            return 2
        elif choose == "0":
            return 0
        else:
            print("输入错误，请重新输入")


def main():
    LoGin = Login.Oprating()
    choose = welcome()
    Name = None

    if choose == 1:

        Name = LoGin.LoginUser()
        print(f"你已打卡：{LoGin.GetDay(Name)[0][0]} 天！")
        if not WordBook.Main(Name).Option():
            LoGin.AddDAY(user=Name, day=int(LoGin.GetDay(Name)[0][0]))
    elif choose == 2:
        Name = LoGin.RegisterUser()
        if Name:
            print(f"你已打卡：{LoGin.GetDay(Name)[0][0]} 天！")
            LogiN = input().strip().upper()
            if LogiN == "是" or LogiN == "Y":
                if not WordBook.Main(Name).Option():
                    LoGin.AddDAY(user=Name, day=int(LoGin.GetDay(Name)[0][0]))
            else:
                print("程序即将退出！")
                time.sleep(1)
                exit(0)
    else:
        exit(0)



if __name__ == '__main__':
    main()